package org.example.modules.Info.controller;

import com.alibaba.fastjson2.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.example.modules.Info.entry.SideJob;
import org.example.modules.Info.sevice.SideJobSevice;
import org.example.modules.user.common.Commsult;
import org.example.modules.user.entry.vo.SideJobMainVo;
import org.example.modules.user.service.SideJobMainService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

/**
 * @Description SideJobController
 * @Author xiaotian
 * @Date 2025-03-22
 */
@RestController
@RequestMapping("/job")
@Slf4j
public class SideJobController {

    @Autowired
    private SideJobMainService sideJobMainSevice;

    @Autowired
    private SideJobSevice sideJobSevice;
    @GetMapping()
    public Commsult<List<SideJobMainVo>> getSideJobList(
            @RequestParam(value = "id", required = false) String id) { // id 参数可选
        if (id != null) {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("Id", id);
            return Commsult.success(Collections.singletonList(sideJobMainSevice.getSideJobDetails(jsonObject)));
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("SubTabType", "0");
        jsonObject.put("TopTabType","0");
        log.info("id is null:{}",sideJobMainSevice.getSideJob(jsonObject));
        return Commsult.success(sideJobMainSevice.getSideJob(jsonObject));
    }
    @PostMapping("updateStatus")
    public Commsult<List<SideJob>> updateStatus(@RequestBody JSONObject data){
        return Commsult.success(sideJobSevice.updateStatus(data));
    }
}
